package com.terracloud.server.dao.model.sql;

import com.terracloud.server.common.data.TenantGroup;
import com.terracloud.server.common.data.id.DeviceGroupId;
import com.terracloud.server.common.data.id.TenantGroupId;
import com.terracloud.server.common.data.id.TenantId;
import com.terracloud.server.dao.model.BaseSqlEntity;
import com.terracloud.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.UUID;

/**
 *
 * @author chenhainan
 * @since 2025/10/11
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "tenant_group")
@NoArgsConstructor
public class TenantGroupEntity extends BaseSqlEntity<TenantGroup> {

    @Column(name = "tenant_id")
    private UUID tenantId;

    @Column(name = ModelConstants.DEVICE_NAME_PROPERTY)
    private String name;

    @Column(name = ModelConstants.DEVICE_PROFILE_DESCRIPTION_PROPERTY)
    private String description;

    @Override
    public TenantGroup toData() {
        final var tenantGroup = new TenantGroup();
        tenantGroup.setId(new TenantGroupId(id));
        tenantGroup.setCreatedTime(createdTime);
        tenantGroup.setName(name);
        tenantGroup.setDescription(description);
        tenantGroup.setTenantId(TenantId.fromUUID(tenantId));
        return tenantGroup;
    }

    public TenantGroupEntity(TenantGroup tenantGroup) {
        this.setId(tenantGroup.getUuidId());
        this.setCreatedTime(tenantGroup.getCreatedTime());
        this.setName(tenantGroup.getName());
        this.setTenantId(tenantGroup.getTenantId().getId());
        this.description = tenantGroup.getDescription();
    }
}
